import { arrayToBar } from "./series.js"
export function initBarOption(list = [], config = {}) {
    let { title, row, column, legendMap = {} } = config

    let xAxis = []
    let series = []


    list.forEach(obj => {
        xAxis.push(obj[row])
    })

    column.forEach(name => {
        let serie = arrayToBar(list, {
            name: legendMap[name],
            key: name,
            type: config.type || 'bar'
        })
        series.push(serie)
    })


    return {
        title: {
            text: title
        },
        xAxis: {
            data: xAxis
        },
        yAxis: {},
        legend: {},
        series: series,

    }
}

export function initPieOption(row, config = {}) {
    let { map, title } = config
    let series = []
    let legend = []
    Object.keys(map).forEach(k => {
        legend.push(map[k])
        series.push({
            value: row[k],
            name: map[k]
        })
    })
    console.log(series);

    return {
        title: {
            text: title,
            left: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            // orient: 'vertical',
            // top: 'middle',
            bottom: 10,
            left: 'center',
            data: legend
        },
        series: [
            {
                name: 'data',
                type: 'pie',
                radius: '55%',
                data: series,
            },

        ],

    }
}